<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2019/1/24
 * Time: 3:45 PM
 */

namespace api\models;


class UserConsumption extends \common\models\UserConsumption
{

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'order_id', 'money', 'type', 'created_at'], 'integer'],
            [
                ['order_id'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => Order::className(),
                'targetAttribute' => ['order_id' => 'id']
            ],
            [
                ['uid'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => User::className(),
                'targetAttribute' => ['uid' => 'id']
            ],
        ];
    }


    public function beforeSave($insert)
    {

        if ($insert) {
            $this->created_at = time();
        }

        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }

}